/*
 * Copyright (c) 2018-2999 九五云信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 */

package com.yami.shop.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.NotifyTemplate;
import com.yami.shop.bean.model.NotifyTemplateShop;
import com.yami.shop.dao.NotifyTemplateShopMapper;
import com.yami.shop.service.NotifyTemplateShopService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 *
 *
 * @author lhd
 * @date 2020-07-04 15:21:20
 */
@Service
@AllArgsConstructor
public class NotifyTemplateShopServiceImpl extends ServiceImpl<NotifyTemplateShopMapper, NotifyTemplateShop> implements NotifyTemplateShopService {

    private final NotifyTemplateShopMapper notifyTemplateShopMapper;


    /**
     * 设置平台或商家的消息通知类型
     * @param notifyTemplate
     * @param template
     */
    @Override
    public void setNotifyTypes(NotifyTemplate notifyTemplate, NotifyTemplateShop template) {
        // 设置平台的消息通知类型
        List<String> notifies = Arrays.asList(notifyTemplate.getTemplateTypes().split(StrUtil.COMMA));
        for (String notify : notifies) {
            notifyTemplate.setSms(StrUtil.equals(notify,"1") ? true:notifyTemplate.getSms());
            notifyTemplate.setSub(StrUtil.equals(notify,"2") ? true:notifyTemplate.getSub());
            notifyTemplate.setApp(StrUtil.equals(notify,"3") ? true:notifyTemplate.getApp());
        }
        if(Objects.isNull(template)){
            return;
        }
        // 设置商家的消息通知类型
        List<String> shopList = Arrays.asList(template.getNotifyTypes().split(StrUtil.COMMA));
        for (String shopNotify : shopList) {
            template.setSms(StrUtil.equals(shopNotify,"1") ? true:template.getSms());
            template.setApp(StrUtil.equals(shopNotify,"3") ? true:template.getApp());
            template.setSub(StrUtil.equals(shopNotify,"2") ? true:template.getSub());
        }
    }
}
